<template>
    <van-address-edit
        :area-list="areaList"
        show-set-default
        :address-info="AddressInfo"
        :area-columns-placeholder="['请选择', '请选择', '请选择']"
        @save="OnSave"
    />
</template>

<script setup>
// 引入省市区数据
import { areaList } from '@vant/area-data';

const { proxy } = getCurrentInstance();

const business = proxy.$business;

// 初始化数据
const AddressInfo = ref({
    name:business.value.nickname,
    tel:business.value.mobile,
    areaCode:business.value.district ? business.value.district : (business.value.city ? business.value.city : business.value.province)
});

const OnSave = async (values) =>
{
    const params = {
        busid:business.value.id,
        consignee:values.name,
        mobile:values.tel,
        code:values.areaCode,
        address:values.addressDetail,
        status:values.isDefault === true ? 1 : 0
    }

    const result = await proxy.$http.post({
        url:'/address/add',
        params
    });

    if(result.code === 1)
    {
        proxy.$success(result.msg,() => proxy.$router.back());
    }else{
        proxy.$fail(result.msg);
    }
}
</script>